﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
// MakePanoForGoogle, Copyright Mirosław M. Mączka.  All Rights Reserved. This code released under the terms of the Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

namespace MakePanoForGoogle
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {

        private void handleTextFile(string [] ll)
        {
            char[] splitchars = { ':' };
            char[] splitcharsGPS = { ',' };
            foreach (string l in ll)
            {
                string lu = l.Trim();
                if ("" == lu) continue;
                if (lu.StartsWith("#") || lu.StartsWith("//")) continue;
                string[] lp = lu.Split(splitchars, 2);
                if (2 != lp.Length) continue;
                switch (lp[0].ToUpper())
                {
                    case "GPS"://Latitude,Longitude
                        {
                            string[] lalo = lp[1].Split(splitcharsGPS, 2);
                            if(2 != lalo.Count())
                            {
                                //MessageBox.Show("Invalid value!", "GPS");
                                break;
                            }
                            double gpsla;
                            if (double.TryParse(lalo[0].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out gpsla))
                            {
                                formLatitude = gpsla;
                            }
                            else
                            {
                                //MessageBox.Show("Invalid value!", "GPS - Latitude");
                            }
                            double gpslo;
                            if (double.TryParse(lalo[1].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out gpslo))
                            {
                                formLongitude = gpslo;
                            }
                            else
                            {
                                //MessageBox.Show("Invalid value!", "GPS - Longitude");
                            }
                        }
                        break;
                    case "GPSLA"://Latitude
                        {
                            double gpsla;
                            if (double.TryParse(lp[1].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out gpsla))
                            {
                                formLatitude = gpsla;
                            }
                        }
                        break;
                    case "GPSLO"://Longitude
                        {
                            double gpslo;
                            if (double.TryParse(lp[1].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out gpslo))
                            {
                                formLongitude = gpslo;
                            }
                        }
                        break;
                    case "DESCRIPTION":
                        {
                            txtDescription.Text = lp[1].Trim();
                        }
                        break;
                    case "DAY":
                        {
                            DateTime dt = DateTime.Now;
                            formDayTaken = dt;
                            if (DateTime.TryParse(lp[1], System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out dt))
                            {
                                formDayTaken = dt;
                            }
                        }
                        break;
                    case "HS"://Horizonatal Span
                        {
                            double hs;
                            if (double.TryParse(lp[1].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out hs))
                            {
                                formHorizontalSpan = hs;
                            }
                        }
                        break;
                    case "VS"://Vertical Span
                        {
                            double vs;
                            if (double.TryParse(lp[1].Trim(), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out vs))
                            {
                                formVerticalSpan = vs;
                            }
                        }
                        break;
                    case "D":
                        {
                            formDescription = lp[1];
                        }
                        break;
                }
            }

        }

    }//class
}//namespace
